import { InfiniteScroll, NavBar } from "antd-mobile";
import React, { useEffect, useState } from "react";
import { useLocation, useNavigate } from "react-router-dom";
import axios from "../../api/axios";
import Formlist from "../../component/Formlist";
function Index() {
  const { state } = useLocation();
  const { start, end } = state;
  const [user, setUset] = useState([]);
  const [page, setPage] = useState(1);
  const get = async () => {
    const resp = await axios.post("/trip/train", { start, end, page });
    console.log(resp);
    setUset(user.concat(resp.data.data));
    setPage(page + 1);
  };
  useEffect(() => {
    get();
  }, []);
  const nav=useNavigate()
  const getDetail=(v)=>{
    console.log(v);
    nav('/xq',{state:v})
  }
  return (
    <div>
      <NavBar>
        {start}-{end}
      </NavBar>
      {user.map((v, i) => {
        return <Formlist key={i} v={v} onClick={()=>getDetail(v)}></Formlist>;
      })}
      <InfiniteScroll loadMore={get} hasMore={true} />
    </div>
  );
}

export default Index;
